package com.itbird.eventbus.core;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by itbird on 2022/9/20
 */
public class BackgroundPoster<T> implements Poster<T> {
    EventBus eventBus;
    ExecutorService executorService = Executors.newCachedThreadPool();

    public BackgroundPoster(EventBus eventBus) {
        this.eventBus = eventBus;
    }

    @Override
    public void enqueue(SubscribeMethod subscription, T event) {
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                eventBus.reflectCallSubscribeMethod(event, subscription);
            }
        });
    }
}
